package com.futvan.z.erp.erpaccrecharge;
import com.futvan.z.erp.erp_account.Erp_accountService;
import com.futvan.z.framework.common.bean.Result;
import com.futvan.z.framework.core.z;
import org.springframework.stereotype.Controller;
import org.springframework.beans.factory.annotation.Autowired;
import com.futvan.z.framework.core.SuperAction;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

@Controller
public class ErpaccrechargeAction extends SuperAction{
	@Autowired
	private ErpaccrechargeService erpaccrechargeService;

	@Autowired
	private Erp_accountService erp_accountService;


	/**
	 * 批量充值
	 * @param bean
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/accRecharges")
	public @ResponseBody Result accRecharges(@RequestParam HashMap<String,String> bean) throws Exception {
		Result result = new Result();
		String zids = bean.get("zids");
		int i = 0;
		if(z.isNotNull(zids)){
			String [] zids_array = zids.split(",");
			for (String zid : zids_array) {
				erp_accrecharge c =  sqlSession.selectOne("erp_accrecharge_select_zid",zid);
				if(z.isNotNull(c)){
					//直接入账
					Result r = erp_accountService.Add(c.getCustomid(),c.getAcc_type(),c.getAmount(),"0","3",c.getZid());
					if(r.ifSuccess()){
						int n = sqlSession.update("update","update erp_accrecharge set isok = '1' where zid = '"+zid+"'");
						if(n==1){
							i= i+1;
						}else{
							z.Exception("批量充值出错|更新erp_accrecharge,isok返回n="+n);
						}
					}
				}
			}

			result.setSuccess(i);
		}else{
			result.setError("zids is null");
		}
		return result;
	}

}
